<?php
require_once dirname(__FILE__) . '/common.inc.php';
$myPdo = DbUtils::createPdoInst();

$customer_id = (MiscUtils::getParam('cid', 0));
$type = (MiscUtils::getParam('type', -1));
$psd = (MiscUtils::getParam('pass', ''));
$user = (MiscUtils::getParam('u', ''));

$pass = 'zheshimimi';

if ($psd == $pass) {
	if ($customer_id != 0) {
	  $cond_vals = new stdClass();
    $cond_vals->c = "t.customer_id=$customer_id";
    $cond_vals->v = array();
    $tmps = DbUtils::get($myPdo, TABLE_NAME_PREFIX_MODULE . 'data_enquiry', $cond_vals, NULL, NULL, NULL, NULL, NULL)->d;
    if (count($tmps) > 0) {
      $tmp = $tmps[0];
      if ($type != -1) {
	      $tmp->customer_id = 0;
	      $tmp->status = 0;
	      $tmp->processing_reason = ($type == 0) ? 'Orders are deleted' : 'Customer is deleted';
	      DbUtils::update($myPdo, TABLE_NAME_PREFIX_MODULE . 'data_enquiry', $tmp);
	      
	      $history = new stdClass();
	      $history->track_id = MiscUtils::unique();
	      $history->enquiry_id = $tmp->id;
	      $history->date1 = date('Y-m-d H:i:s', time());
	      $history->status = 0;
	      $history->description = 'Back to processing: ' . (($type == 0) ? 'Orders are deleted' : 'Customer is deleted');
	      $history->operator_id = 0;
	      $history->operator_name = $user;
	      DbUtils::add($myPdo, TABLE_NAME_PREFIX_MODULE . 'data_enquiry_followup_history', $history);
	      echo json_encode(array());
      }
    }
	}
}

?>
